<template>
	<view>
		<view class="member">
			<view class="member-item">
				<navigator :url="`/pageSubOne/company/company-department?companyId=${companyId}`">
					<view class="item">
						<svg-icon icon="成员与部门" :width="96"></svg-icon>
						<text>成员与部门</text>
					</view>
				</navigator>
				<navigator url="/pageSubOne/company/company-employee-application">
					<view class="item">
						<svg-icon icon="新成员申请" :width="96"></svg-icon>
						<text>新成员申请</text>
					</view>
				</navigator>
			</view>
		</view>
		<view class="add-member">
			<view class="add" v-for="item in company">
				<text>{{ item.text }}</text>
				<view class="member-item">
					<view class="item" v-for="it in item.item" :key="it.text" @tap="navigateTo(it.url)">
						<svg-icon :icon="it.icon" :width="96"></svg-icon>
						<text>{{ it.text }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			companyId: {
				type: Number,
				default: null
			},
			isAdmin:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				company: [{
						text: "添加成员",
						item: [{
								icon: "邀请加入",
								text: "邀请加入",
								url: "/pageSubOne/company/company-invite-join"
							},
							{
								icon: "链接邀请",
								text: "链接邀请",
								url: "/pageSubOne/company/company-link-invitation"
							},
							{
								icon: "邀请记录",
								text: "邀请记录",
								url: "/pageSubOne/company/company-invitation-record"
							}
						]
					},
					{
						text: "通讯录管理",
						item: [{
								icon: "负责人",
								text: "负责人",
								url: "/pageSubOne/company/company-set-responsible-person"
							},
							{
								icon: "角色管理",
								text: "角色管理",
								url: "/pageSubOne/company/company-role-setting"
							},
							{
								icon: "管理员",
								text: "管理员",
								url: "/invite-join"
							},
							{
								icon: "征用商友号",
								text: "征用商友号",
								url: "/pageSubOne/company/company-friend-business-name"
							}
						]
					},
					{
						text: "企业信息",
						item: [{
								icon: "企业认证",
								text: "企业认证",
								url: "/pageSubOne/company/company-certification"
							},
							{
								icon: "LOGO&标题",
								text: "LOGO&标题",
								url: "/pageSubOne/company/company-logo"
							},
							{
								icon: "官网绑定",
								text: "官网绑定",
								url: "/pageSubOne/company/company-official-website-binding"
							},
							{
								icon: "群聊设置",
								text: "群聊设置",
								url: "/pageSubOne/company/company-group-chat-settings"
							},
							{
								icon: "聊天背景",
								text: "聊天背景",
								url: "/pageSubOne/company/company-chat-background"
							},
							{
								icon: "客户管理",
								text: "客户管理",
								url: "/invite-join"
							},
							{
								icon: "活跃指数",
								text: "活跃指数",
								url: "/invite-join"
							},
							{
								icon: "企业认证",
								text: "公司简介",
								url: "/pageSubOne/business-chat/business-profile"
							},
							{
								icon: "聊天背景",
								text: "相册",
								url: "/pageSubOne/business-chat/components/picture-panel/index"
							},
							{
								icon: "wifi",
								text: "WI-FI管理",
								url: "/invite-join"
							}
						]
					}
				]
			}
		},
		mounted() {
			console.log(this.isAdmin)
			// 1. 找到企业信息配置项
			const enterpriseInfo = this.company.find(item => item.text === "企业信息");
			if(this.isAdmin){
				enterpriseInfo.item.push({
				      icon: "解散企业",      // 图标
				      text: "解散公司",        // 显示文本
				      url: "/dismiss"       // 路由路径
				});	
			}else{
				enterpriseInfo.item.push({
				      icon: "解散企业",      // 图标
				      text: "退出公司",        // 显示文本
				      url: "/quitCompany"       // 路由路径
				});	
			}

		},
		computed: {

		},
		methods: {
			navigateTo(url) {
				console.log("url", url)
				 if (url === "/dismiss") {
				      this.handleDismissCompany();
				    }
				
				
				if (this.companyId) {
					if(url=="/invite-join"){
						uni.showToast({
							title:"待开发敬请期待",
							icon:"none"
						})
					}else{
						uni.navigateTo({
							url: `${url}?companyId=${this.companyId}`
						});
					}
				} else {
					uni.navigateTo({
						url
					});
				}
			},
			  
			  // 解散公司专用逻辑
			  handleDismissCompany() {
				  console.log("123")
			    uni.showModal({
			      title: "确认解散公司",
			      content: "此操作不可逆，确认解散吗？",
			      success: (res) => {
			        if (res.confirm) {
			          this.dismissCompanyApi();
			        }
			      }
			    });
			  },
			  
			  // 调用解散公司的 API
			  async dismissCompanyApi() {
			    const res = await this.$http({
			        url: `/company/dismissCompany?companyId=${this.companyId}`,
			        method: "DELETE"
			      });
				uni.showToast({ title: "解散公司成功", icon: "none" });
			    uni.navigateBack({ delta: 1 }); // 返回上一页 
			  },
		}
	}
</script>

<style lang="less" scoped>
	.member {
		width: 100%;

		.member-item {
			padding: 30rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				gap: 24rpx;
				font-size: 30rpx;
			}
		}
	}

	.add-member {
		width: 100%;
		
		padding-bottom: 120rpx;

		.add {
			padding: 30rpx;

			.member-item {
				// padding: 30rpx;
				display: flex;
				flex-wrap: wrap;
				align-items: center;
				margin-top: 32rpx;

				.item {
					width: 150rpx;
					margin: 10rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					gap: 24rpx;
					font-size: 26rpx;

				}
			}
		}
	}
</style>